import {reactive, ref} from "vue";
import http from "../http";
import doctor from "./doctor.js";
import settings from "../settings.js";
const answer = reactive({
    imageUrlList: [],
    imageList: [],
    question: "",
    answer_list: {},
    doctor_id: "",
    doctor_info: {},
    answer_info: {},
    order_info: {},
    star_answer: {},
    get_answer_history(token){
        this.doctor_id = localStorage.getItem("doctor_id")
        return http.post(`/doctor/get_answer/`, {
            doctor: this.doctor_id
            }, {
            headers: {
                Authorization: "Bearer " + token
            }
        }).then(response=>{
                console.log(response.data.data)
                this.question = response.data.data[0].answer.user_content;
                for (let i =0; i < response.data.data[0].image_list.length; i++) {
                    this.imageUrlList.push({'url': settings.host + response.data.data[0].image_list[i].image.slice(1)})
                }
        })
    },
    get_answer_info(token, answer_id, doctor_id, order_id){
        let data = {
            answer_id: answer_id,
            doctor_id: doctor_id,
            order_id: order_id
        }
        console.log(data)

        return http.post(`/doctor/get_answer/`, data, {
            headers: {
                Authorization: "Bearer " + token
            }
        }).then(response=>{
            console.log(response.data.data)
            this.answer_info = response.data.data.answer_info;
            this.doctor_info = response.data.data.doctor_info;
            this.doctor_info.avatar = settings.host + this.doctor_info.avatar.slice(1)
            this.order_info = response.data.data.order_info;
        })
    },
    get_star_answer(doctor_id){
        return http.get(`/doctor/doctor_star_info/${doctor_id}/`).then(response=>{
            this.star_answer = response.data.data;
            console.log(this.star_answer)
        })
    },

})

export default answer;